package day07;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class StreamTest02 {

    private final static List<Person> list = Person.list();

    public static void main(String[] args) {
        test5();
    }

    protected static void test1() {
        boolean b = list.stream().allMatch(e -> e.getAge() > 123);
        System.out.println("是否全部大于123岁：" + b);

        boolean l = list.stream().noneMatch(e -> e.getName().equals("雷布斯"));
        System.out.println("是否包含雷布斯：" + l);

        Optional<Person> first = list.stream().findFirst();
        System.out.println(first);

        Optional<Person> any = list.parallelStream().findAny();
        System.out.println(any);
    }

    protected static void test2() {
        long count = list.size();
        System.out.println("总共数量：" + count);
    }

    protected static void test3() {
        List<Integer> integers = Arrays.asList(12, 32, 41, 21, -321, 323);

        Integer reduce = integers.stream().reduce(0, Integer::sum);
        System.out.println("总合：" + reduce);
    }

    protected static void test4() {
        Optional<Integer> reduce = list.stream().map(Person::getAge).reduce(Integer::sum);
        System.out.println("总年龄：" + reduce);
    }

    protected static void test5() {
        list.stream().filter(p -> p.getAge() > 123).collect(Collectors.toSet()).forEach(System.out::println);
    }
}
